#!/opt/miniconda3/bin/python

import sys
import os
from hashlib import md5
from pathlib import Path


def get_file_md5(file_name, segment_counts):
    """ 
        Calculate partial content md5 value of big file, 
        but its not the true md5 value of the file.
    """
    file_path = Path(file_name).absolute().as_posix()
    file_size = os.stat(file_path).st_size
    file_md5 = md5()
    file = open(file_path, 'rb')
    for i in range(segment_counts):
        file.seek(int(file_size/segment_counts)*i)
        file_md5.update(file.read(1024))
    file_md5.update(str(file_size).encode('ascii'))
    print(file_md5.hexdigest(), '\t', file_path)
    file.close()

if __name__ == '__main__':
    file_name = sys.argv[1]
    segment_counts = int(sys.argv[2])
    get_file_md5(file_name, segment_counts)
